﻿using Separation.Token.Entity;
using System;
using System.Collections.Generic;
using System.Text;

namespace Separation.Token
{
    public enum Role 
    {
        Admin,
        Users,
        Visitors
    }
    public class RoleHelper
    {
        public RoleHelper() 
        {
            Roles = new List<string>();
        }
        public  RoleHelper(string roleString) 
        {
            Roles = new List<string>(roleString.Split(','));
        }
        public RoleHelper(TokenModel tkm)
        {
            Roles = new List<string>(tkm.Role.Split(','));
        }
        public List<string> Roles { get; private set; }
        public string Role
        {
            get
            {
                var roleString = "";
                foreach (var item in Roles)
                {
                    if (roleString != string.Empty)
                        roleString += "," + item;
                    else
                        roleString += item;
                }
                return roleString;
            }
        }
        public string ChangeRole(params Role[] roles) 
        {
            this.Roles.Clear();
            foreach (var item in roles)
            {
                Roles.Add(item.ToString());
            }
            return this.Role;
        }
        public string AddRole(params Role[] role)
        {
            foreach (var item in role)
            {
                Roles.Add(item.ToString());
            }
            return this.Role;
        }
        public string SubRole(Role role)
        {
            Roles.Remove(role.ToString());
            return this.Role;
        }
        public string ClearRole(Role role)
        {
            Roles.Clear();
            return this.Role;
        }
    }
}
